<template>
  <div class="driver-info-dialog">
    <div class="driver-info">
      <div class="avatar"></div>
      <div class="detail">
        <div class="top">
          <div class="name">{{driverName}}</div>
          <div class="sex">{{driverSex}}</div>
        </div>
        <div class="position">{{driverType}}</div>
      </div>
    </div>
    <div class="info-list">
      <div class="info-item" v-for="(item, index) in driverInfoList" :key="index">
        {{item.label}}{{item.value}}
      </div>
    </div>
    <div class="operation-list">
      <div class="operation-btn info">档案信息</div>
      <div class="operation-btn analysis">轨迹分析</div>
      <div class="operation-btn inspect">背景审查</div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { getRealTimeBusDriverInfo } from 'api/situationAwareness/busWay/screenCenter'
import Bus from 'utils/eventBus'
@Component({
  name: 'driver-info-dialog'
})

export default class DriverInfoDialog extends Vue {
  private driverInfoList: any[] = [
    { label: '身份证：', value: '' },
    { label: '联系电话：', value: '' },
    { label: '公司：', value: '' },
    { label: '驾龄', value: '' }
  ]

  private driverName = ''
  private driverSex = ''
  private driverType = ''

  created () {
    Bus.$off('showBusWayDriverDialog', this.getRealTimeBusDriverInfo.bind(this))
    Bus.$on('showBusWayDriverDialog', this.getRealTimeBusDriverInfo.bind(this))
  }

  async getRealTimeBusDriverInfo ({ driverId }: { driverId: string }) {
    const params = {
      driver: driverId
    }
    try {
      const res = await getRealTimeBusDriverInfo(params)
      console.log('公交线路-驾驶员详情', res)
      const { empname, sexName, empptypename, idcard, telephone, orgname, driveryear } = res.data
      this.driverName = empname
      this.driverSex = sexName
      this.driverType = empptypename
      this.driverInfoList = [
        { label: '身份证：', value: idcard },
        { label: '联系电话：', value: telephone },
        { label: '公司：', value: orgname },
        { label: '驾龄', value: `${driveryear}年` }
      ]
    } catch (err) {
      console.error('公交线路-驾驶员详情', err)
    }
  }
}
</script>

<style lang="scss" scoped>
.driver-info-dialog {
  width: 280px;
  height: 300px;
  background: url('../../../../assets/images/situational-awareness/driver-info-dialog-bg.png') no-repeat;
  background-size: 100% 100%;
  box-sizing: border-box;
  padding: 23px 25px 0px;
  position: absolute;
  bottom: 0px;
  left: -140px;
  .driver-info {
    display: flex;
    align-items: center;
    .avatar {
      width: 90px;
      height: 100px;
      background: #ffffff;
      margin-right: 18px;
    }
    .detail {
      width: calc(100% - 90px - 18px);
      height: 100px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      overflow: hidden;
      .top {
        .name {
          font-size: 18px;
          line-height: 30px;
          font-family: 'PingFang Regular';
          color: #fff;
        }
        .sex {
          font-size: 14px;
          line-height: 26px;
          font-family: 'PingFang Regular';
          font-weight: 400;
          color: #fff;
        }
      }
      .position {
        font-size: 16px;
        line-height: 24px;
        font-family: 'PingFang Regular';
        font-weight: 400;
        color: #fbcf31;
      }
    }
  }
  .info-list {
    margin-top: 16px;
    .info-item {
      width: 100%;
      box-sizing: border-box;
      padding-left: 18px;
      font-size: 14px;
      line-height: 26px;
      font-family: 'PingFang Regular';
      font-weight: 400;
      color: #fff;
      position: relative;
      white-space: nowrap;
      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 9px;
        width: 8px;
        height: 8px;
        background: #fbcf31;
        border-radius: 50%;
      }
    }
  }
  .operation-list {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-around;
    margin-top: 10px;
    .operation-btn {
      width: 70px;
      height: 24px;
      text-align: center;
      line-height: 24px;
      border-radius: 12px;
      font-size: 14px;
      font-family: 'PingFang Regular';
      font-weight: 400;
      &.info {
        border: 1px solid #0173ff;
        color: #39adff;
      }
      &.analysis {
        border: 1px solid #009944;
        color: #1bbc32;
      }
      &.inspect {
        border: 1px solid #e71f19;
        color: #ff3131;
      }
    }
  }
}
</style>
